import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import './assets/css/base.css'

Vue.use(VueAxios, axios)
Vue.config.productionTip = false
Vue.use(ElementUI);

axios.interceptors.request.use(config => {
  if (config.url != '/login' && config.url != '/register') {
    if (localStorage['token']) {
      config.headers.common['Authorization'] = localStorage['token']
    }
  }
  return config
})
axios.interceptors.response.use(config => {
  return config
},
err => {
  console.log('err:',err)
  if(err.response.status==401){
    window.location.href="/login"
  }
})
axios.defaults.baseURL = 'http://localhost:3000/'

new Vue({
  router,
  store,
  render: h => h(App),
  beforeCreate(){
  Vue.prototype.$bus=this
  }
}).$mount('#app')
